package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    /**
     * 新增商机跟进记录
     * @param businessTrackVo 商机跟进记录信息
     * @return AjaxResult
     */
    @Override
    public Integer add(BusinessTrackVo businessTrackVo) {
        TbBusiness tbBusiness = new TbBusiness();
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();

        BeanUtils.copyProperties(businessTrackVo, tbBusiness);
        tbBusiness.setId(businessTrackVo.getBusinessId());
        // 更新商机中的客户信息
        tbBusinessTrackRecordMapper.updateTbBusinessById(tbBusiness);


        BeanUtils.copyProperties(businessTrackVo, tbBusinessTrackRecord);
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());
        // 插入商机跟进记录
        return tbBusinessTrackRecordMapper.addTbBusinessTrackRecord(tbBusinessTrackRecord);
    }

    /**
     * 查询商机跟进记录列表
     * @param id 商机ID
     * @return TbBusinessTrackRecord 商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> getByBusinessId(Long id) {
        return tbBusinessTrackRecordMapper.getByBusinessId(id);
    }
}
